﻿<html>

	<head>
		<meta charset="utf-8">
		<title>个人资料</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/base2.css" />
		<style>
			label {
				width: 10%;
				color: #0094ff
			}
			
			input {
				width: 90%;
			}
			
			#head {
				line-height: 40px;
			}
			
			#head-img1 {
				width: 40px;
				height: 40px;
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">个人信息</h1>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<a id="head">头像
						<span class="mui-pull-right head">
						<img class="image mui-media-object mui-pull-left" src="#" id="userimg"/>
					</span>
					</a>
				</li>
			</ul>
			<h4 id="accout"></h4>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>用户名:</label>
					<input type="text" id="txtuser" readonly="readonly" placeholder="用户名" />
				</div>
				<!--<div class="mui-input-row">
					<label>姓名:</label>
					<input type="text" id="realname" readonly="readonly" placeholder="姓名" />
				</div>-->
				<div class="mui-input-row">
					<label>性别:</label>
					<input type="text" id="txtsex" readonly="readonly" placeholder="性别">
				</div>
				<div class="mui-input-row">
					<label>手机号码:</label>
					<input type="tel" id="txtphone" readonly="readonly" placeholder="手机号码">
				</div>
				
			</form>
			<!--<div class="mui-input-row">
				<textarea id='txt-memo' rows="6" placeholder="经营范围..."></textarea>
			</div>-->
		</div>

		<script type="text/javascript" src="../js/mui.min.js "></script>
		<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="../js/app.js "></script>
		<script src="../js/wf.js"></script>
		<script src="../js/canvasResize.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init({});
			var files = [];
			//更换头像
			mui(".mui-table-view-cell").on("tap", "#head", function(e) {
				var a = [{
					title: "拍照"
				}, {
					title: "从手机相册选择"
				}];
				plus.nativeUI.actionSheet({
					title: "修改头像",
					cancel: "取消",
					buttons: a
				}, function(b) {
					switch(b.index) {
						case 0:
							break;
						case 1:
							getImage();
							break;
						case 2:
							galleryImg();
							break;
						default:
							break
					}
				})
			});
			//修改
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				var username = self.username;
				var userid = self.userid;
				var value = self.value;
				$("#txtuser").val(username);
				showImg(username);
				var datas = new Object();
				datas.UID = userid;
				wf.ajax("Account/GetUserInfoByUserID", { //?UserName=datas.UserName&Password=datas.password
					data: datas,
					type: "get",
					dataType: "json",
					success: function(resule) {
						if(resule.Code == "20000") {
							$("#txtsex").val(resule.Data.Sex);
							$("#txtphone").val(resule.Data.Phone);
						} else {
							mui.toast(resule.Msg);
						}
					}
				});

				//				

			});

			//			
			//初始化页面内容数据
			function initdata(state) {
				// var state = app.getState();     EduLevel  Interest2    
				// var html = "账号:" + state.login[0].Account ;
				//          oid="";//state.login[0].MemberId;
				//          $('#txtacout').val(state.login[0].Account);
				//          $('#realname').val(state.login[0].RealName);
				//          $('#txtzw').val(state.login[0].Remark);
				//          $('#txtphone').val(state.login[0].Mobile);
				//          $('#txtemail').val(state.login[0].Email);
				//          $('#txtsite').val(state.login[0].CarNo);
				//          $('#txtcomp').val(state.login[0].Interest1);
				//          $('#txtaddr').val(state.login[0].Address);
				//          $('#txt-memo').val(state.login[0].Interest2);

				// alert(JSON.stringify(state))
				//          document.getElementById("head-img1").src =serverAdd + state.login[0].Interest3;

			}

			function getImage() {
				var cmr = plus.camera.getCamera();
				cmr.captureImage(function(p) {
					plus.io.resolveLocalFileSystemURL(p, function(entry) {
						mui.openWindow({
							url: 'cropper.html',
							id: 'cropper.html',
							extras: {
								path: "file:///" + entry.fullPath,
								change: "cem"
							}
						});
					}, function(e) {
						mui.toast(e.message);
					});
				}, function(e) {}, {
					filename: "_doc/camera/"
				});
			}

			function galleryImg() {
				// 从相册中选择图片				 
				plus.gallery.pick(function(path) {
					var fname = path.substring(path.lastIndexOf('/') + 1);
					//mui.openWindow( );
					mui.openWindow({
						url: 'cropper.html',
						id: 'cropper.html',
						extras: {
							path: path,
							change: "open"
						}

					});
				}, function(e) {
					plus.nativeUI.toast("取消选择图片");
				}, {
					filter: "image"
				});
			};
			//随机字符串
			function randomString(len) {　　
				len = len || 32;　　
				var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ 　　
				var maxPos = $chars.length;　　
				var pwd = '';　　
				for(i = 0; i < len; i++) {　　　　
					pwd += $chars.charAt(Math.floor(Math.random() * maxPos));　　
				}　　
				return pwd;
			}

			function callback(data) {
				files.push(data);
				upload();
			}
			// 上传文件
			function upload() {
				if(files.length <= 0) {
					plus.nativeUI.alert("没有添加上传文件！");
					return;
				}
				var datas = new Object();
				datas.FileArr = files.toString();
				datas.username = "User_" + $("#txtuser").val();
				plus.nativeUI.showWaiting();
				wf.ajax("Account/UserPicAdd", {
					traditional: true,
					type: "post",
					data: datas,
					dataType: "json",
					success: function(resule) {
						if(resule.Code == "20000") {
							mui.toast(resule.Msg);
							plus.nativeUI.closeWaiting();
							//							refreshParent();
						} else {
							mui.toast(resule.Msg);
							plus.nativeUI.closeWaiting();
						}

					}
				});

			}

			//			function getBase64Image(img) {
			//				var canvas = document.createElement("canvas");
			//				canvas.width = img.width;
			//				canvas.height = img.height;
			//
			//				var ctx = canvas.getContext("2d");
			//				ctx.drawImage(img, 0, 0, img.width, img.height);
			//
			//				var dataURL = canvas.toDataURL("image/png");
			//				//				return dataURL
			//
			//				return dataURL.replace("data:image/png;base64,", "");
			//			}

			// 产生一个随机数
			function getUid() {
				return Math.floor(Math.random() * 100000000 + 10000000).toString();
			}

			function showImg(username) {
				var picname = "User_" + username;
				var img = document.getElementById("userimg");
				img.setAttribute("src", wf.server_Domain + "FileUpload/ReadPic?name=" + picname);
			}
		</script>
	</body>

</html>